/**
 * Project Name:YCApiServer-Api
 * File Name:UserCenterService.java
 * Package Name:com.yc.music.service.service103
 * Date:2016年5月10日下午1:25:36
 * Copyright (c) 2016 
 *
 */
package com.yc.music.service.service21;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.yc.music.common.context.YcContext;
import com.yc.music.common.util.RoomUtil;
import com.yc.music.context.YtConstant;
import com.yc.music.mapper.cache.MusicActivityCacheMapper;
import com.yc.music.mapper.dao.MusicActivityUserMapper;
import com.yc.music.mapper.dao.MusicActivityWorkMapper;
import com.yc.music.mapper.dao.WorkCommentMapper;
import com.yc.music.model.activity.MusicActivityLyricsVo;
import com.yc.music.model.activity.MusicActivityUserVo;
import com.yc.music.model.activity.MusicActivityVo;
import com.yc.music.model.activity.MusicActivityWorkVo;
import com.yc.music.model.comment.YcComment;
import com.yc.music.service.service103.CommentService;

/**
 * 
 * ClassName: MusicActivityWorkService <br/>
 * Function: 活动作品. <br/>
 * Reason: TODO ADD REASON(可选). <br/>
 * date: 2016年8月16日 下午2:32:17 <br/>
 *
 * @author qinhaiguan
 * @version
 */
@Service
public class MusicActivityWorkService {

	@Value("${Pic_QiLiu}")
	private String pIC_QiLiu;
	
	@Value("${Audio_QiLiu}")
	private String audio_QiLiu;
	
	@Autowired
	private MusicActivityWorkMapper musicActivityWorkMapper;
	
	@Autowired
	private CommentService commentService;
	
	@Autowired
	private WorkCommentMapper workCommentMapper;
	
	@Autowired
	private MusicActivityCacheMapper musicActivityCacheMapper;

	/**
	 * 
	 * musicActivityWork:活动作品列表. <br/> 
	 * @param aid  活动id
	 * @param type  类型  1表示歌曲 2表示歌词
	 * @param sort  排序方式  0表示最新 1表示最热
	 * @param page  页码
	 * @param result
	 * @return
	 * @throws Exception
	 * @since JDK 1.7
	 */
	public Map<String,Object> musicActivityWorkList(Integer aid,Integer type,Integer sort,Integer page,Map<String,Object> result) throws Exception {
		int rows=10;
		page=page==0?page=1:page;
		int start=(page-1)*rows;
		List<MusicActivityWorkVo> workLlist=null;
		List<MusicActivityLyricsVo> lyricLlist=null;
		if (1==type) {
			//获取歌曲的列表
			workLlist=musicActivityWorkMapper.getActivityWorkList(aid, sort,type, start, rows);
			for (MusicActivityWorkVo vo : workLlist) {
				vo.setHeadurl(RoomUtil.jointDomain(vo.getHeadurl(),pIC_QiLiu));
				vo.setPic(RoomUtil.jointDomain(vo.getPic(),pIC_QiLiu));
				vo.setMp3(RoomUtil.jointDomain(vo.getMp3(),audio_QiLiu));
				//获取歌曲作品的id  vo.getWorkid()
				//获取该作品的评论列表
				List<YcComment> listComment=commentService.geCcommentList(vo.getItemid(), page, result, type);
				vo.setListComment(listComment);
				//获取歌曲作品的评论条数
				int count=workCommentMapper.geWorkCommentCount(vo.getItemid(), type);
				vo.setCommentnum(count);
			}
			
			result.put(YcContext.CODE, 200);
			result.put(YcContext.MESSAGE,YtConstant.SYS_SUCCSS_MSG);
			result.put(YcContext.DATA, workLlist);
			return result;
		}else{
			//获取歌词的列表
			lyricLlist=musicActivityWorkMapper.getActivityLyricsList(aid, sort,type, start, rows);
			for (MusicActivityLyricsVo vo : lyricLlist) {
				vo.setHeadurl(RoomUtil.jointDomain(vo.getHeadurl(),pIC_QiLiu));
				vo.setPic(RoomUtil.jointDomain(vo.getPic(),pIC_QiLiu));
				//获取歌词作品的id  vo.getLyricsid()
				//获取该作品的评论列表
				List<YcComment> listComment=commentService.geCcommentList(vo.getItemid(), page, result, type);
				vo.setListComment(listComment);
				
				//获取歌曲作品的评论条数
				int count=workCommentMapper.geWorkCommentCount(vo.getItemid(), type);
				vo.setCommentnum(count);
			}
			
			result.put(YcContext.CODE, 200);
			result.put(YcContext.MESSAGE, YtConstant.SYS_SUCCSS_MSG);
			result.put(YcContext.DATA, lyricLlist);
			return result;
		}
		
		
	}
	
	/**
	 * 
	 * musicActivityWork:活动作品列表. <br/> 
	 * @param aid  活动id
	 * @param result
	 * @return
	 * @throws Exception
	 * @since JDK 1.7
	 */
	public Map<String,Object> musicActivityOverList(Integer aid,Map<String,Object> result) throws Exception {
		//查询活动得类型
		//先查询
		MusicActivityVo musicActivityVo=musicActivityCacheMapper.getMusicActivityById(aid);
		List<MusicActivityWorkVo> workLlist=null;
		List<MusicActivityLyricsVo> lyricLlist=null;
		if (0==musicActivityVo.getType()) {
			//获取歌曲的列表
			workLlist=musicActivityWorkMapper.getActivityWorkOverList(aid,musicActivityVo.getType()+1);
			for (MusicActivityWorkVo vo : workLlist) {
				vo.setHeadurl(RoomUtil.jointDomain(vo.getHeadurl(),pIC_QiLiu));
				vo.setPic(RoomUtil.jointDomain(vo.getPic(),pIC_QiLiu));
				vo.setMp3(RoomUtil.jointDomain(vo.getMp3(),audio_QiLiu));
				//获取歌曲作品的id  vo.getWorkid()
				//获取该作品的评论列表
				List<YcComment> listComment=commentService.geCcommentList(vo.getItemid(), 1, result, musicActivityVo.getType()+1);
				vo.setListComment(listComment);
				//获取歌曲作品的评论条数
				int count=workCommentMapper.geWorkCommentCount(vo.getItemid(), musicActivityVo.getType()+1);
				vo.setCommentnum(count);
			}
			
			result.put(YcContext.CODE, 200);
			result.put(YcContext.MESSAGE,YtConstant.SYS_SUCCSS_MSG);
			result.put(YcContext.DATA, workLlist);
			return result;
		}else {
			//获取歌词的列表
			lyricLlist=musicActivityWorkMapper.getActivityLyricsOverList(aid,musicActivityVo.getType()+1);
			for (MusicActivityLyricsVo vo : lyricLlist) {
				vo.setHeadurl(RoomUtil.jointDomain(vo.getHeadurl(),pIC_QiLiu));
				vo.setPic(RoomUtil.jointDomain(vo.getPic(),pIC_QiLiu));
				//获取歌词作品的id  vo.getLyricsid()
				//获取该作品的评论列表
				List<YcComment> listComment=commentService.geCcommentList(vo.getItemid(), 1, result, musicActivityVo.getType()+1);
				vo.setListComment(listComment);
				
				//获取歌曲作品的评论条数
				int count=workCommentMapper.geWorkCommentCount(vo.getItemid(), musicActivityVo.getType()+1);
				vo.setCommentnum(count);
			}
			
			result.put(YcContext.CODE, 200);
			result.put(YcContext.MESSAGE, YtConstant.SYS_SUCCSS_MSG);
			result.put(YcContext.DATA, lyricLlist);
			return result;
		}
		
		
	}
	
}
